﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class TestCase_TestTwoGrid : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InitGrid1();
        InitGrid2();
        InitGrid3();
        
    }

    

    private void InitGrid1()
    {
        this.dotNetFlexGrid1.InitConfig(
            new string[]{
                "title=false",//标题
                "singleselected=true",//是否单选
                "resizable=false",//是否可以调整大小
                "usepager=true",//使用分页器
                "showcheckbox=true",//显示复选框
                "height=200",//高度，可为auto或具体px值
                "width=340",//宽度，可为auto或具体px值
                "striped=false",//是否显示行交替色
                "selectedonclick=true"//是否点击行自动选中checkbox
            },
            new dotNetFlexGrid.FieldConfig[]{
                new dotNetFlexGrid.FieldConfig("Guid","编号",200,true,dotNetFlexGrid.FieldConfigAlign.Center,false,true,true),
                new dotNetFlexGrid.FieldConfig("String1","字段1",100,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("String2","字段2",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true),
                new dotNetFlexGrid.FieldConfig("String3","字段3",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true),
                new dotNetFlexGrid.FieldConfig("String4","字段4",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true),
                new dotNetFlexGrid.FieldConfig("Int1","字段5",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("Int2","字段6",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true),
                new dotNetFlexGrid.FieldConfig("DateTime","字段7",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("Checked","字段8",60,false,dotNetFlexGrid.FieldConfigAlign.Left,false,true,false)
            });
        this.dotNetFlexGrid1.DataHandler = new dotNetFlexGrid.DataHandlerDelegate(_Grid1Handle);
    }
    
    private void InitGrid2()
    {
        this.dotNetFlexGrid2.InitConfig(
            new string[]{
                "title=false",//标题
                "singleselected=true",//是否单选
                "resizable=false",//是否可以调整大小
                "usepager=true",//使用分页器
                "showcheckbox=true",//显示复选框
                "height=200",//高度，可为auto或具体px值
                "width=340",//宽度，可为auto或具体px值
                "striped=false",//是否显示行交替色
                "selectedonclick=true"//是否点击行自动选中checkbox
            }, 
            new dotNetFlexGrid.FieldConfig[]{
                new dotNetFlexGrid.FieldConfig("Guid","编号",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true),
                new dotNetFlexGrid.FieldConfig("String1","字段1",120,true,dotNetFlexGrid.FieldConfigAlign.Right,false,true,true),
                new dotNetFlexGrid.FieldConfig("String2","字段2",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true),
                new dotNetFlexGrid.FieldConfig("String3","字段3",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true),
                new dotNetFlexGrid.FieldConfig("String4","字段4",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true),
                new dotNetFlexGrid.FieldConfig("Int1","字段5",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("Int2","字段6",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true),
                new dotNetFlexGrid.FieldConfig("DateTime","字段7",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("Checked","字段8",60,false,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true)
            });
        this.dotNetFlexGrid2.DataHandler = new dotNetFlexGrid.DataHandlerDelegate(_Grid2Handle);
    }
    private void InitGrid3()
    {
        this.dotNetFlexGrid3.InitConfig(
            new string[]{
                "title=标题",//标题
                "singleselected=false",//是否单选
                "resizable=true",//是否可以调整大小
                "usepager=true",//使用分页器
                "showcheckbox=true",//显示复选框
                "height=200",//高度，可为auto或具体px值
                "width=auto",//宽度，可为auto或具体px值
                "striped=true",//是否显示行交替色
                "selectedonclick=true"//是否点击行自动选中checkbox
            },
            new dotNetFlexGrid.FieldConfig[]{
                new dotNetFlexGrid.FieldConfig("Guid","编号",60,true,dotNetFlexGrid.FieldConfigAlign.Left,false,true,true),
                new dotNetFlexGrid.FieldConfig("String1","字段1",240,true,dotNetFlexGrid.FieldConfigAlign.Right),
                new dotNetFlexGrid.FieldConfig("String2","字段2",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("String3","字段3",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("String4","字段4",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("Int1","字段5",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("Int2","字段6",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("DateTime","字段7",60,true,dotNetFlexGrid.FieldConfigAlign.Left),
                new dotNetFlexGrid.FieldConfig("Checked","字段8",60,false,dotNetFlexGrid.FieldConfigAlign.Left,true,true,false)
            },
            null,
            new dotNetFlexGrid.ExtParamConfig[]
            {
                new dotNetFlexGrid.ExtParamConfig("defaultSearch","中文啦1"),//配置若干个传递参数
                new dotNetFlexGrid.ExtParamConfig("defaultSearch2","中文啦2"),//配置若干个传递参数
                new dotNetFlexGrid.ExtParamConfig("defaultSearch3","中文啦3"),//配置若干个传递参数
            }
            );
        this.dotNetFlexGrid3.DataHandler = new dotNetFlexGrid.DataHandlerDelegate(_Grid3Handle);
        this.dotNetFlexGrid3.DefaultSearch.Add("中文参数","参数测试AAA!@#$%^&*()");
        this.dotNetFlexGrid3.DefaultSearch.Add("$中文参数2", "参数测试AAA!@#$%^&*()");
    }
    /// <summary>
    /// 主表数据源
    /// </summary>
    /// <param name="p"></param>
    /// <returns></returns>
    public dotNetFlexGrid.DataHandlerResult _Grid1Handle(dotNetFlexGrid.DataHandlerParams p)
    {
        return dotNetFlexGrid.DemoDataHandler(p); ;
    }
    //从表数据源
    public dotNetFlexGrid.DataHandlerResult _Grid2Handle(dotNetFlexGrid.DataHandlerParams p)
    {
        dotNetFlexGrid.DataHandlerResult result = new dotNetFlexGrid.DataHandlerResult();
        result.page = p.page;
        result.total = 100;
        result.table = dotNetFlexGrid.DemoMemoryTable(p.page * 100, p.rp);
        if (p.defaultSearch != null && p.defaultSearch.Count > 0)
        {
            string search = string.Empty;
            foreach (string key in p.defaultSearch.Keys)
                search += "key=" + key + "|value=" + p.defaultSearch[key] + ";";
            result.table.Rows[0][1] = search;
        }
        if (p.extParam.ContainsKey("MasterTableId"))
        {
            DataView dv = result.table.DefaultView;
            dv.RowFilter = "Int1>" + p.extParam["MasterTableId"];
            result.table = dv.ToTable();
            if (p.extParam.ContainsKey("用于测试的"))
            {
                result.table.Rows[0][2] = p.extParam["用于测试的"];
            }
        }
        if (p.sortname.Length > 0 && p.sortorder.Length > 0)
        {
            DataView dv = result.table.DefaultView;
            dv.Sort = (p.sortname + " " + p.sortorder);
            result.table = dv.ToTable();
        }

        return result;
    }
    //从从表数据源
    public dotNetFlexGrid.DataHandlerResult _Grid3Handle(dotNetFlexGrid.DataHandlerParams p)
    {
        dotNetFlexGrid.DataHandlerResult result = new dotNetFlexGrid.DataHandlerResult();
        result.page = p.page;
        result.total = 100;
        result.table = dotNetFlexGrid.DemoMemoryTable(p.page * 100, p.rp);
        if (p.defaultSearch != null && p.defaultSearch.Count > 0)
        {
            string search = string.Empty;
            foreach (string key in p.defaultSearch.Keys)
                search += "key=" + key + "|value=" + p.defaultSearch[key] + ";";
            result.table.Rows[0][1] = search;
        }
        if (p.extParam.ContainsKey("MasterTableId"))
        {
            DataView dv = result.table.DefaultView;
            dv.RowFilter = "Int1<" + p.extParam["MasterTableId"];
            result.table = dv.ToTable();
        }
        if (p.sortname.Length > 0 && p.sortorder.Length > 0)
        {
            DataView dv = result.table.DefaultView;
            dv.Sort = (p.sortname + " " + p.sortorder);
            result.table = dv.ToTable();
        }

        return result;
    }
}
